const px2rem = require('postcss-px2rem')
const path = require('path');
const postcss = px2rem({
  remUnit: 140
})

function resolve(dir) {
  return path.join(__dirname, dir)
}
const os=require('os');
function getNetworkIp(){
  let needHost='';//打开的host
  try{
    //获取网络接口列表
    let network =os.networkInterfaces();
    for(let dev in network){
      let iface=network[dev]
      for(let i=0;i<iface.length;i++){
        let alias=iface[i];
        if(alias.family==='IPv4'&&alias.address!=='127.0.0.1'&&!alias.internal){
          needHost=alias.address;
          break;
        }
      }
    }
  } catch(e){
    needHost='localhost'
  }
  return needHost
}
module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          postcss
        ]
      }
    }
  },
  chainWebpack(config){
    config.resolve.alias.set("@assets", resolve('src/assets'));
},
  devServer: {
    open: true,
  },
  // 配置跨域
  devServer: {
    proxy: {
      '/api': {
        // target: 'http://192.168.43.146:8082',
        target: 'http://127.0.0.1:8081',
        changeOrigin: true,
        pathRewrite: {
          "^/api": "" // rewrite path
        }
      }
    },
    host:getNetworkIp(),
    port:8085
  },
  chainWebpack: config => {
    config.resolve.alias.set("@assets", resolve('src/assets'));
    config.plugins.delete('prefetch');
    config.plugins.delete('preload');
  },
  productionSourceMap: false
}
